/*     */ package com.zimbra.cs.object;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.LogFactory;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Zimlet;
/*     */ import com.zimbra.cs.zimlet.ZimletConfig;
/*     */ import com.zimbra.cs.zimlet.ZimletException;
/*     */ import com.zimbra.cs.zimlet.ZimletHandler;
/*     */ import com.zimbra.cs.zimlet.ZimletUtil;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class ObjectHandler
/*     */ {
/*  43 */   private static Log mLog = LogFactory.getLog(ObjectHandler.class);
/*     */   private static List<ObjectHandler> mHandlerList;
/*     */   private final Zimlet mObjectType;
/*     */   private final ZimletHandler mHandlerObject;
/*     */   private final ZimletConfig mConfigObject;
/*     */   
/*     */   private ObjectHandler(Zimlet obj)
/*     */     throws ObjectHandlerException, ZimletException
/*     */   {
/*  52 */     this.mObjectType = obj;
/*  53 */     this.mHandlerObject = ZimletUtil.getHandler(obj.getName());
/*  54 */     if (this.mHandlerObject == null) {
/*  55 */       throw new ObjectHandlerException("null handler for " + obj.getType());
/*     */     }
/*  57 */     this.mConfigObject = new ZimletConfig(obj.getHandlerConfig());
/*     */     
/*  59 */     String regex = obj.getServerIndexRegex();
/*  60 */     if (regex != null) {
/*  61 */       this.mConfigObject.setRegExValue(regex);
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public static synchronized List<ObjectHandler> getObjectHandlers()
/*     */     throws ServiceException
/*     */   {
/*  70 */     if (mHandlerList != null) {
/*  71 */       return mHandlerList;
/*     */     }
/*  73 */     mHandlerList = new ArrayList();
/*  74 */     List<Zimlet> dots = Provisioning.getInstance().listAllZimlets();
/*  75 */     for (Iterator<Zimlet> it = dots.iterator(); it.hasNext();) {
/*  76 */       Zimlet dot = (Zimlet)it.next();
/*  77 */       ObjectHandler handler = loadHandler(dot);
/*  78 */       if (handler != null) {
/*  79 */         mHandlerList.add(handler);
/*     */       }
/*     */     }
/*  82 */     return mHandlerList;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   private static synchronized ObjectHandler loadHandler(Zimlet dot)
/*     */   {
/*  90 */     ObjectHandler handler = null;
/*  91 */     String clazz = dot.getHandlerClassName();
/*  92 */     if (clazz == null) {
/*  93 */       return null;
/*     */     }
/*     */     try {
/*  96 */       handler = new ObjectHandler(dot);
/*     */     } catch (Exception e) {
/*  98 */       if (mLog.isErrorEnabled())
/*  99 */         mLog.error("loadHandler caught exception", e);
/*     */     }
/* 101 */     return handler;
/*     */   }
/*     */   
/*     */   public void parse(String text, List<MatchedObject> matchedObjects, boolean firstMatchOnly) throws ObjectHandlerException
/*     */   {
/*     */     try {
/* 107 */       String[] matchedStrings = this.mHandlerObject.match(text, this.mConfigObject);
/* 108 */       for (int i = 0; i < matchedStrings.length; i++) {
/* 109 */         MatchedObject mo = new MatchedObject(this, matchedStrings[i]);
/* 110 */         matchedObjects.add(mo);
/* 111 */         if (firstMatchOnly)
/* 112 */           return;
/*     */       }
/*     */     } catch (ZimletException ze) {
/* 115 */       throw new ObjectHandlerException("error running ZimletHandler " + this.mObjectType.getType(), ze);
/*     */     }
/*     */   }
/*     */   
/*     */   public String getType() {
/* 120 */     return this.mObjectType.getType();
/*     */   }
/*     */   
/*     */   public String getHandlerConfig() {
/* 124 */     return this.mObjectType.getHandlerConfig();
/*     */   }
/*     */   
/*     */   public String getDescription() {
/* 128 */     return this.mObjectType.getDescription();
/*     */   }
/*     */   
/*     */   public boolean isIndexingEnabled() {
/* 132 */     return this.mObjectType.isIndexingEnabled();
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/object/ObjectHandler.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */